package company;

import java.util.*;

public class ThreeSum {
    public static void main(String[] args) {
        // 输入
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String replace = s.replace("[", "");
        String replace1 = replace.replace("]", "");
        String[] split = replace1.split(",");
        int len = split.length;
        int[] digit = new int[len];
        for (int i = 0; i < len; i++) {
            digit[i] = Integer.parseInt(split[i]);
        }

        // 获取符合条件的组合
        Set<List<Integer>> list = threeSum(digit);

        // 打印
        if (list.size() == 0) {
            System.out.println("[]");
        }
        System.out.print("[[");
        int size = list.size();
        int i = 0;
        for (List sublist: list) {
            i++;
            int size1 = sublist.size();
            for (int j = 0; j < size1; j++) {
                System.out.print(sublist.get(j));
                if (j < size1 - 1) {
                    System.out.print(",");
                }
            }
            if (i < size - 1) {
                System.out.print("],[");
            } else {
                System.out.print("]]");
            }
        }
    }


    public static Set<List<Integer>> threeSum(int[] nums) {
        // 排序
        int[] ints = Arrays.stream(nums).sorted().toArray();
        Set<List<Integer>> list = new HashSet<>();
        List<Integer> subList;
        int len = nums.length;
        for (int i = 0; i < len; i++) {
            int a = ints[i];
            subList = new ArrayList<>();

            // 定义指针
            int left = i + 1;
            int right = len - 1;

            // 双指针
            for (int j = i + 1; j < len; j++) {
                if (left < right) {
                    // b+c +a < 0
                    if (ints[left] + ints[right] + a < 0) {
                        left++;
                    } else if (ints[left] + ints[right] + a == 0) {
                        // b+c+a = 0
                        subList.add(a);
                        subList.add(ints[left]);
                        subList.add(ints[right]);
                        break;
                    } else if (ints[left] + ints[right] + a > 0) {
                        right--;
                    }
                }
            }
            if (0 != subList.size()) {
                list.add(subList);
            }
        }
        return list;
    }
}
